package balance_change_type

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetBalanceChangeTypeListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 余额变动类型列表
func NewGetBalanceChangeTypeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBalanceChangeTypeListLogic {
	return &GetBalanceChangeTypeListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetBalanceChangeTypeListLogic) GetBalanceChangeTypeList() (resp *types.GetBalanceChangeTypeListReqs, err error) {
	result, err := l.svcCtx.AssetsRpc.Config.GetConfigInOutList(l.ctx, &rpc.GetConfigInOutListRq{})
	if err != nil {
		return nil, err
	}
	var list = make([]types.GetBalanceChangeTypeList, 0)
	for _, row := range result.GetList() {
		list = append(list, types.GetBalanceChangeTypeList{
			Id:      row.GetId(),
			TypeId:  row.GetTypeId(),
			Name:    row.Name,
			Value:   row.Value,
			TagType: int(row.TagType),
		})
	}
	return &types.GetBalanceChangeTypeListReqs{List: list}, nil
}
